home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / qltk / ratingsmenu.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  3KB  |  70 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. from gi.repository import Gtk
  5. from quodlibet import util
  6. from quodlibet import config
  7. from quodlibet import qltk
  8. from quodlibet.config import RATINGS
  9. from quodlibet.qltk import SeparatorMenuItem
  10. from quodlibet.util import connect_obj
  11.  
  12. class ConfirmRateMultipleDialog(qltk.Message):
  13.     
  14.     def __init__(self, parent, count, value):
  15.         if not count > 1:
  16.             raise AssertionError
  17.         title = None('Are you sure you want to change the rating of all %d songs?') % count
  18.         desc = _('The saved ratings will be removed') if value is None else _("The rating of all selected songs will be changed to '%s'") % util.format_rating(value)
  19.         super(ConfirmRateMultipleDialog, self).__init__(Gtk.MessageType.WARNING, parent, title, desc, Gtk.ButtonsType.NONE)
  20.         self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_APPLY, Gtk.ResponseType.YES)
  21.  
  22.  
  23.  
  24. class RatingsMenuItem(Gtk.MenuItem):
  25.     __accels = Gtk.AccelGroup()
  26.     
  27.     def set_rating(self, value, songs, librarian):
  28.         count = len(songs)
  29.         if count > 1 and config.getboolean('browsers', 'rating_confirm_multiple'):
  30.             dialog = ConfirmRateMultipleDialog(self, count, value)
  31.             if dialog.run() != Gtk.ResponseType.YES:
  32.                 return None
  33.         for song in songs:
  34.             song['~#rating'] = value
  35.         
  36.         librarian.changed(songs)
  37.  
  38.     
  39.     def remove_rating(self, songs, librarian):
  40.         count = len(songs)
  41.         if count > 1 and config.getboolean('browsers', 'rating_confirm_multiple'):
  42.             dialog = ConfirmRateMultipleDialog(self, count, None)
  43.             if dialog.run() != Gtk.ResponseType.YES:
  44.                 return None
  45.         reset = []
  46.         for song in songs:
  47.             if '~#rating' in song:
  48.                 del song['~#rating']
  49.                 reset.append(song)
  50.                 continue
  51.         librarian.changed(reset)
  52.  
  53.     
  54.     def __init__(self, songs, library, label = _('_Rating')):
  55.         super(RatingsMenuItem, self).__init__(label = label, use_underline = True)
  56.         submenu = Gtk.Menu()
  57.         self.set_submenu(submenu)
  58.         for i in RATINGS.all:
  59.             itm = Gtk.MenuItem(label = '%0.2f\t%s' % (i, util.format_rating(i)))
  60.             submenu.append(itm)
  61.             connect_obj(itm, 'activate', self.set_rating, i, songs, library)
  62.         
  63.         reset = Gtk.MenuItem(label = _('_Remove rating'), use_underline = True)
  64.         connect_obj(reset, 'activate', self.remove_rating, songs, library)
  65.         submenu.append(SeparatorMenuItem())
  66.         submenu.append(reset)
  67.         submenu.show_all()
  68.  
  69.  
  70.